import imageio
import os

def create_gif(image_list, gif_name, duration = 0.05):
    '''
    :param image_list: 这个列表用于存放生成动图的图片
    :param gif_name: 字符串，所生成gif文件名，带.gif后缀
    :param duration: 图像间隔时间
    :return:
    ''' 
    frames = []
    for image_name in image_list:
        frames.append(imageio.imread(image_name))

    imageio.mimsave(gif_name, frames, 'GIF', duration=duration)
    return

def generate_fig():
    #这里放上自己所需要合成的图片
    picture_path = './picture/'
    picture_list = []
    for filename in os.listdir(picture_path):
        if filename[-3:]!='png':
            continue
        picture_list.append(picture_path+filename)
        picture_list.sort()
        
    gif_name = picture_path+'process.gif'
    duration = 0.05
    if picture_list:
        create_gif(picture_list, gif_name, duration)

if __name__ == '__main__':
    generate_fig()
